import datetime
from applications.extensions import db


class ReportType(db.Model):
    __tablename__ = 'admin_report_type'
    id = db.Column(db.Integer, primary_key=True)
    type_name = db.Column(db.String(255), comment='报表类型名称')
    type_code = db.Column(db.String(255), unique=True,comment='报表类型标识')
    description = db.Column(db.String(255), comment='报表类型描述')
    enable = db.Column(db.Integer, comment='是否开启')
    create_time = db.Column(db.DateTime, default=datetime.datetime.now, comment='创建时间')
    update_time = db.Column(db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, comment='更新时间')


class ReportData(db.Model):
    __tablename__ = 'admin_report_data'
    id = db.Column(db.Integer, primary_key=True)
    data_label = db.Column(db.String(255),  nullable=False,comment='文件名称')
    data_value = db.Column(db.String(255), comment='报表类型查看顺序')
    type_code = db.Column(db.String(255), comment='报表类型描述')
    default = db.Column(db.Integer, comment='是否默认' ,default=0)
    enable = db.Column(db.Integer, comment='是否开启',default=0)
    remark = db.Column(db.String(255), comment='备注')
    href = db.Column(db.String(255), comment='文件路由路径')
    mime = db.Column(db.CHAR(255), nullable=False, comment='文件类型')
    size = db.Column(db.CHAR(30), nullable=False , comment='文件大小')
    create_time = db.Column(db.DateTime, default=datetime.datetime.now, comment='创建时间')
    update_time = db.Column(db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, comment='更新时间')
    def to_dict(self):
        return {column.name: getattr(self, column.name) for column in self.__table__.columns}